package com.nari.ies.ne.nw.server.service.fileScore.impl;

import com.nari.ies.ne.nw.server.entity.PvFileScoreEntity;
import com.nari.ies.ne.nw.server.entity.WindFileScoreEntity;
import com.nari.ies.ne.nw.server.mapper.FileScoreMapper;
import com.nari.ies.ne.nw.server.service.fileScore.IFileScoreService;
import com.nari.ies.ne.nw.server.service.fileScore.IXBFZFileScoreService;
import com.nari.ies.ne.nw.server.util.DataUtil;
import com.nari.ies.ne.nw.server.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class XBFZFileScoreServiceImpl implements IXBFZFileScoreService {
    @Autowired
    private FileScoreMapper fileScoreMapper;
    @Autowired
    private IFileScoreService fileScoreService;
    @Override
    public PvFileScoreEntity XBFZFileScore(PvFileScoreEntity pvFileScoreEntity) {
        String plantId = pvFileScoreEntity.getPlantId();
        //今天00:00
        Date endDate = pvFileScoreEntity.getDateTime();
        Date startDate = DateUtil.getYesterdayTime(endDate);
        String fileType = "XB-FZ";
        String plantType = "GF";
        String tableName="HISDB.NW_NE_FILE_DATACHECK_GF_XBFZ";

        //上送文件数量
        int XB_FZNum = fileScoreMapper.selectFileNumData(tableName,plantId, fileType, plantType, startDate, endDate);
        //文件满分
        float XB_FZFullScore = fileScoreMapper.selectFileFullScore(fileType, plantType);
        //完整率
        float XB_FZRate = 0;
        //文件上送率
        float XB_FZSendRate = 0;
        //文件得分
        float XB_FZScore = 0;
        //文件合格率
        float XB_FZQualifiedRate = 0;

        if (XB_FZNum > 0) {
            //文件上送率
            XB_FZSendRate = 100;
            XB_FZRate = (float) XB_FZNum / 96 * 100;
            //文件数据项总得分
            float fileDataScore = fileScoreService.getFileDataScore(plantId, fileType, plantType, startDate, endDate,tableName);
            //文件得分
            XB_FZScore = fileDataScore;
            //文件合格率
            XB_FZQualifiedRate = XB_FZScore / XB_FZFullScore * 100;
        }else {
            XB_FZRate=0;
            XB_FZScore=0;
            XB_FZSendRate=0;
            XB_FZQualifiedRate=0;
        }
        pvFileScoreEntity.setXB_FZNum(XB_FZNum);
        pvFileScoreEntity.setXB_FZRate(XB_FZRate);
        pvFileScoreEntity.setXB_FZScore(XB_FZScore);
        pvFileScoreEntity.setXB_FZFullScore(XB_FZFullScore);
        pvFileScoreEntity.setXB_FZQualifiedRate(XB_FZSendRate);
        pvFileScoreEntity.setXB_FZSendRate(XB_FZQualifiedRate);

        return pvFileScoreEntity;
    }
}
